/**
 * 
 */
package component.activemq;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * 
 * @author liuboen
 * 
 * since:2012-6-7
 * version:1.0.0
 */
public class TopicSend {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// ConnectionFactory ：连接工厂，JMS 用它创建连接 
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( 
                        ActiveMQConnection.DEFAULT_USER, 
                        ActiveMQConnection.DEFAULT_PASSWORD, 
                        "tcp://127.0.0.1:61616"); 
        
        try {
        	Connection connection= connectionFactory.createConnection();
        	connection.start();
        	 Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); 
        	 Topic topic = session.createTopic("test-topic");
        	 
        	  // MessageProducer：消息生产者 
             MessageProducer producer = session.createProducer(topic); 
             //设置不持久化 
             producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
             
             //创建一条文本消息 
             MapMessage message = session.createMapMessage();
             message.setBoolean("bl", Boolean.TRUE);
             message.setString("tst", "fsdfdsfsdfsd");
             //通过消息生产者发出消息 
             producer.send(message); 
             session.commit();
             
             producer.close();
             session.close();
             connection.close();
		} catch (JMSException e) {
			e.printStackTrace();
		}finally{
			
		}
	}

}
